package com.example.myapplication.Sign;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.example.myapplication.R;

// 用户协议类
public class UserAgreement {

    // 用户协议部分
    private TextView agreement;

    private Context context;

    UserAgreement(TextView agreement,Context context){
        this.agreement = agreement;
        this.context = context;
    }

    // 设置用户协议-改变颜色和设置事件
    public void setAgreement(){
        SpannableString spannableString = new SpannableString("已阅读并同意《用户协议》和《隐私协议》");
        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override
            public void onClick(@NonNull View view) {

            }

            @Override
            public void updateDrawState(@NonNull TextPaint ds) {
                ds.setColor(ContextCompat.getColor(context, R.color.hehe_blue));
                ds.setUnderlineText(false);
            }
        };

        spannableString.setSpan(clickableSpan, 6, 12, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);

        ClickableSpan clickableSpan2 = new ClickableSpan() {
            @Override
            public void onClick(View view) {


            }

            @Override
            public void updateDrawState(TextPaint ds) {
                ds.setColor(ContextCompat.getColor(context, R.color.hehe_blue));//设置颜色
                ds.setUnderlineText(false);//去掉下划线
            }

        };

        spannableString.setSpan(clickableSpan2, 13, 19, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);

        ForegroundColorSpan colorSpan = new ForegroundColorSpan(ContextCompat.getColor(context, R.color.hehe_blue));
        spannableString.setSpan(colorSpan, 6, 12, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);

        ForegroundColorSpan colorSpan2 = new ForegroundColorSpan(ContextCompat.getColor(context, R.color.hehe_blue));
        spannableString.setSpan(colorSpan2, 13, 19, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);

        agreement.setText(spannableString);
        agreement.setMovementMethod(LinkMovementMethod.getInstance());

    }




}
